package org.lhh.server.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@SuppressWarnings("all")
public class JSONArray extends ArrayList<Object> {

	private static final long serialVersionUID = 1L;

	public JSONArray() {

	}

	public JSONArray(int initialCapacity) {
		super(initialCapacity);
	}

	public JSONArray(List<Object> list) {
		if(list != null)
			this.addAll(list);
	}

	public static JSONArray fromObject(String json){
		JSONArray jsonArray = new JSONArray();
		if(StringUtils.isEmpty(json))
			return jsonArray;
		return JsonUtils.jsonToBean(json, JSONArray.class);
	}

	public String getString(int i) {
		return (String) get(i);
	}

	public JSONObject getJSONObject(int i) {
		Map<String, Object> m = (Map<String, Object>) get(i);
		return new JSONObject(m);
	}

	public String toString() {
		return JsonUtils.beanToJson(this);
	}
}
